import requests
class ConfigHttp():
    def __init__(self,dic):
        self.interfaceUrl = dic['interfaceUrl']
        self.method = dic['method']
        # 传入参数需要检查这里的参数的数据类型是否有问题，post接口中只能存在字典类型或者json数据类型，不能用其他的数据类型
        self.value = eval(dic['value'])
        self.header = eval(dic['header'])
        print(f'{self.interfaceUrl}--------{self.method}-----------{self.value}-------{self.header}')
    def run(self):
        if self.method == 'get':
            res = self.__get()
        elif self.method == 'post:form':
            res = self.__post_form()
        elif self.method == 'post:json':
            res = self.__post_json()
        return res
    def __get(self):
        res = requests.get(url=self.interfaceUrl, params=self.value,headers=self.header)
        return res
    def __post_form(self):
        res = requests.post(url=self.interfaceUrl, data=self.value,headers=self.header)
        return res
    def __post_json(self):
        res = requests.post(url=self.interfaceUrl, json=self.value,headers=self.header)
        return res
if __name__ == '__main__':
    from common.readData import ReadData
    rd=ReadData()
    data=rd.read_excel(1)
    print(data)
    ch=ConfigHttp(data[0])
    res=ch.run()
    print(res.text)
